/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.CommentResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.DataResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.HistoricProcessInstanceQueryRequest
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.HistoricProcessInstanceResponse

/**
 * HistoryProcess
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface HistoryProcessApi {


    /**
     * List of historic process instances
     */
    @GetMapping("/history/historic-process-instances")
    fun listHistoricProcessInstances(
        @RequestParam(name = "processInstanceId", required = false) processInstanceId: String?,
        @RequestParam(name = "processInstanceName", required = false) processInstanceName: String?,
        @RequestParam(name = "processInstanceNameLike", required = false) processInstanceNameLike: String?,
        @RequestParam(
            name = "processInstanceNameLikeIgnoreCase",
            required = false
        ) processInstanceNameLikeIgnoreCase: String?,
        @RequestParam(name = "processDefinitionKey", required = false) processDefinitionKey: String?,
        @RequestParam(name = "processDefinitionId", required = false) processDefinitionId: String?,
        @RequestParam(name = "processDefinitionName", required = false) processDefinitionName: String?,
        @RequestParam(name = "processDefinitionCategory", required = false) processDefinitionCategory: String?,
        @RequestParam(name = "processDefinitionVersion", required = false) processDefinitionVersion: String?,
        @RequestParam(name = "deploymentId", required = false) deploymentId: String?,
        @RequestParam(name = "businessKey", required = false) businessKey: String?,
        @RequestParam(name = "businessKeyLike", required = false) businessKeyLike: String?,
        @RequestParam(name = "activeActivityId", required = false) activeActivityId: String?,
        @RequestParam(name = "involvedUser", required = false) involvedUser: String?,
        @RequestParam(name = "finished", required = false) finished: Boolean?,
        @RequestParam(name = "superProcessInstanceId", required = false) superProcessInstanceId: String?,
        @RequestParam(name = "excludeSubprocesses", required = false) excludeSubprocesses: Boolean?,
        @RequestParam(name = "finishedAfter", required = false) finishedAfter: String?,
        @RequestParam(name = "finishedBefore", required = false) finishedBefore: String?,
        @RequestParam(name = "startedAfter", required = false) startedAfter: String?,
        @RequestParam(name = "startedBefore", required = false) startedBefore: String?,
        @RequestParam(name = "startedBy", required = false) startedBy: String?,
        @RequestParam(name = "includeProcessVariables", required = false) includeProcessVariables: Boolean?,
        @RequestParam(name = "callbackId", required = false) callbackId: String?,
        @RequestParam(name = "callbackType", required = false) callbackType: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "tenantIdLike", required = false) tenantIdLike: String?,
        @RequestParam(name = "withoutTenantId", required = false) withoutTenantId: Boolean?
    ): R<DataResponse<HistoricProcessInstanceResponse>>

    /**
     * Get a historic process instance
     */
    @GetMapping("/history/historic-process-instances/{processInstanceId}")
    fun getHistoricProcessInstance(
        @PathVariable("processInstanceId") processInstanceId: String
    ): R<HistoricProcessInstanceResponse>

    /**
     *  Delete a historic process instance
     */
    @DeleteMapping("/history/historic-process-instances/{processInstanceId}")
    fun deleteHistoricProcessInstance(
        @PathVariable("processInstanceId") processInstanceId: String
    ): R<Any>

    /**
     * List comments on a historic process instance
     */
    @GetMapping("/history/historic-process-instances/{processInstanceId}/comments")
    fun listHistoricProcessInstanceComments(
        @PathVariable("processInstanceId") processInstanceId: String
    ): R<Any>

    /**
     * Parameter saveProcessInstanceId is optional, if true save process instance id of task with comment.
     */
    @PostMapping("/history/historic-process-instances/{processInstanceId}/comments")
    fun createComment(
        @PathVariable("processInstanceId") processInstanceId: String,
        @RequestBody(required = false) body: CommentResponse?
    ): R<CommentResponse>

    /**
     * Get a comment on a historic process instance
     */
    @GetMapping("/history/historic-process-instances/{processInstanceId}/comments/{commentId}")
    fun getComment(
        @PathVariable("processInstanceId") processInstanceId: String,
        @PathVariable("commentId") commentId: String
    ): R<CommentResponse>

    /**
     * Delete a comment on a historic process instance
     */
    @DeleteMapping("/history/historic-process-instances/{processInstanceId}/comments/{commentId}")
    fun deleteComment(
        @PathVariable("processInstanceId") processInstanceId: String,
        @PathVariable("commentId") commentId: String
    ): R<Any>

    /**
     * List identity links of a historic process instance
     */
    @GetMapping("/history/historic-process-instances/{processInstanceId}/identitylinks")
    fun listHistoricProcessInstanceIdentityLinks(
        @PathVariable("processInstanceId") processInstanceId: String
    ): R<Any>

    /**
     * The response body contains the binary value of the variable. When the variable is of type binary, the content-type of the response is set to application/octet-stream, regardless of the content of the variable or the request accept-type header. In case of serializable, application/x-java-serialized-object is used as content-type.
     */
    @GetMapping("/history/historic-process-instances/{processInstanceId}/variables/{variableName}/data")
    fun getHistoricProcessInstanceVariableData(
        @PathVariable("processInstanceId") processInstanceId: String,
        @PathVariable("variableName") variableName: String
    ): R<Any>

    /**
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic process instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     */
    @PostMapping("/query/historic-process-instances")
    fun queryHistoricProcessInstance(
        @RequestBody(required = false) body: HistoricProcessInstanceQueryRequest?
    ): R<DataResponse<HistoricProcessInstanceResponse>>
}